# -*- coding: utf-8 -*-
"""
Created on Sat Sep 11 18:08:10 2021

@author: chibi
"""

import cv2
from PIL import Image
 
img = cv2.imread('test.png', cv2.IMREAD_UNCHANGED)
 
#print('Original Dimensions : ',img.shape)
 
#scale_percent = 60 # percent of original size
#width = int(img.shape[1] * scale_percent / 100)
#height = int(img.shape[0] * scale_percent / 100)
dim = (128, 64)
  
# resize image
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
im = Image.fromarray(cv2.cvtColor(resized,cv2.COLOR_BGR2RGB))
#im.show()
#im = im.convert("L")
im = im.convert("1")
text =''
point = 0
for y in range (64):
    for x in range (128):
        if im.getpixel((x,y)) <150:
            get_point = 0
        else:
            get_point = 1
            
        
        now = int( get_point )<<(3-x%4) 
        #位数1/0 转二进制
       
        point += now
        
        if (x%4 ==3):
            text += hex(point)[2:]
           
            #text += "|"
            point = 0 #还原

print(text)
#print('Resized Dimensions : ',resized.shape)
 
#cv2.imshow("Resized image", resized)
#cv2.waitKey(0)
#cv2.destroyAllWindows()